package mysgoog.gtp;

import mysgoog.bot.*;

public class Vertex
{
    public int x, y;

    public Vertex(int pos)
    {
        this.x = Config.getEmptyBoard().posX(pos);
        this.y = Config.getEmptyBoard().posY(pos);
    }
    public Vertex(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    public Vertex(String s)
    {
        if (s.equalsIgnoreCase("pass"))
        {
            x = -1;
            y = -1;
            return;
        }
        s = s.toUpperCase();
        char c = s.charAt(0);
        if (c >= 'J')
            c--;
        x = c - 'A';
        y = Integer.parseInt(s.substring(1)) - 1;
    }
    @Override
    public String toString()
    {
        if (x == -1 && y == -1)
            return "pass";
        char c = (char) ('A' + x);
        if (c >= 'I')
            c++;
        return "" + c + (y + 1);
    }
    public boolean isPass()
    {
        return x == -1 && y == -1;
    }
    
    public boolean equals(Object o){
		if (!(o instanceof Vertex)) return false;
		Vertex v = (Vertex)o;
		if ((this.x == v.x) && (this.y == v.y)) return true;
		return false;
    }
}
